<template>
  <div>
    <div class="app-container calendar-list-container">
      <div class="filter-container">
        <el-input @keyup.enter.native="" style="width: 200px;" class="filter-item" :placeholder="'标题'" v-model="listQuery.title">
        </el-input>
        <el-select clearable class="filter-item" style="width: 130px" v-model="listQuery.type" :placeholder="'类型'">
          <el-option v-for="item in  calendarTypeOptions" :key="item.key" :label="item.display_name+'('+item.key+')'" :value="item.key">
          </el-option>
        </el-select>
        <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="">搜索</el-button>
        <el-button class="filter-item" style="margin-left: 10px;" @click="" type="primary" icon="el-icon-edit">添加</el-button>
      </div>

      <el-table :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row
        style="width: 100%">
        <el-table-column align="center" :label="'序号'" width="65">
          <template slot-scope="scope">
            <span>{{scope.row.id}}</span>
          </template>
        </el-table-column>
        <el-table-column min-width="150px" :label="'标题'">
          <template slot-scope="scope">
            <span>{{scope.row.name}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" :label="'操作'" width="230" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="">编辑</el-button>
            <el-button size="mini" type="danger" @click="">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.perPage" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
    </div>
    <edit-add></edit-add>
  </div>
</template>
<script>
import { fetchComboList } from '@/api/combo'
import EditAdd from './components/edit_add'
import waves from '@/directive/waves' // 水波纹指令
export default {
  name: 'combosManager',
  directives: {
    waves
  },
  components: {
    EditAdd
  },
  data() {
    return {
      tableKey: 0,
      list: [
        {id: 0, timestamp: '123'},
        {id: 1, timestamp: '456'}
      ],
      total: null,
      listLoading: false,
      listQuery: {
        page: 1,
        perPage: 20,
        title: undefined,
        type: undefined
      },
      calendarTypeOptions: [
        {key: '0', display_name: '123'},
        {key: '1', display_name: '456'}
      ],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchComboList(this.listQuery).then(response => {
        this.list = response.data.items
        this.total = response.data.total
        this.listLoading = false
      })
    },
    handleSizeChange() {
    },
    handleCurrentChange() {
    }
  }
}
</script>